#include <ansi_c.h>
#define SIZE 9
#define nr 'n'
#define bl 'b'
#define ab ' '
#define x 'x'
#define tmp 'X'
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DE RETOURNE PION N/B DES FONCTIONS*/
void bl_return_pion(int ,int,int);
int  bl_return_ht_gch(int ,int,int);
int  bl_return_ht_ct(int ,int,int);
int  bl_return_ht_drt(int ,int,int);
int  bl_return_ml_gch(int ,int,int);
int  bl_return_ml_drt(int ,int,int);
int  bl_return_bs_gch(int ,int,int);
int  bl_return_bs_ct(int ,int,int);
int  bl_return_bs_drt(int ,int,int);
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
void nr_return_pion(int ,int,int);
int  nr_return_ht_gch(int ,int,int);
int  nr_return_ht_ct(int ,int,int);
int  nr_return_ht_drt(int ,int,int);
int  nr_return_ml_gch(int ,int,int);
int  nr_return_ml_drt(int ,int,int);
int  nr_return_bs_gch(int ,int,int);
int  nr_return_bs_ct(int ,int,int);
int  nr_return_bs_drt(int ,int,int);
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DETECTION N/B DES FONCTIONS*/  
void bl_detection(int  tab[SIZE][SIZE]);
int  bl_case_haut_gauche(int ,int,int);
int  bl_case_haut_centre(int ,int,int);   
int  bl_case_haut_droite(int ,int,int);  
int  bl_case_milieu_gauche(int ,int,int);  
int  bl_case_milieu_droite(int ,int,int);  
int  bl_case_bas_gauche(int ,int,int);   
int  bl_case_bas_centre(int ,int,int);  
int  bl_case_bas_droite(int ,int,int);
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
void nr_detection(int  tab[SIZE][SIZE]);
int  nr_case_haut_gauche(int ,int,int);
int  nr_case_haut_centre(int ,int,int);   
int  nr_case_haut_droite(int ,int,int);  
int  nr_case_milieu_gauche(int ,int,int);  
int  nr_case_milieu_droite(int ,int,int);  
int  nr_case_bas_gauche(int ,int,int);   
int  nr_case_bas_centre(int ,int,int);  
int  nr_case_bas_droite(int ,int,int);
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
													   /*VARIABLES GENERALE*/
int  tab[SIZE+1][SIZE]= { {ab,'1','2','3','4','5','6','7','8'},
						  {'1',ab,ab,ab,ab,ab,ab,ab,ab},
 				 		  {'2',ab,ab,ab,ab,ab,ab,ab,ab},		
 						  {'3',ab,ab,ab,ab,ab,ab,ab,ab},
 				 		  {'4',ab,ab,ab,bl,nr,ab,ab,ab},
						  {'5',ab,ab,ab,nr,bl,ab,ab,ab},
						  {'6',ab,ab,ab,ab,ab,ab,ab,ab},
 					      {'7',ab,ab,ab,ab,ab,ab,ab,ab},
						  {'8',ab,ab,ab,ab,ab,ab,ab,ab},
					  };
int colonne;
int ligne;
int  case_next;
int k=0;
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION MAIN*/
void main(void)
{
 int i;
 int j;
 int pion_b=0;
 int pion_n=0;
 printf("\t\t\t\t\tJOUEUR BLANC");
 bl_detection(tab);
 printf("\n\t\t\t\t\tJOUEUR BLANC");
 printf("\t\t\t\t\tPAS DE POSSIBILITE DE RETOURNER UN PION ADVERSE\n");
 printf("\t\t\t\t\t FIN DU JEU\n");
 for(i=0;i<SIZE;i++)				 
 {									 
  printf("\n");
  for(j=0;j<SIZE;j++)				  
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
    pion_b=pion_b+1;
   else if (tab[i][j]==nr)
    pion_n=pion_n+1;
  }
  printf("\n");
 }
 printf("\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",pion_b,pion_n);
 
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE DE DETECTION DES PIONS B*/
void bl_detection(int  tab[SIZE][SIZE])
{
 int i;
 int j;
 int pion_b=0;
 int pion_n=0;
 int pion_x=0;
 int  save;
 for(i=1 ; i<SIZE ; i++)
 {
  for(j=1 ; j<SIZE ; j++)
  {
   if(tab[i][j]==bl)
   {
	if(i>1 && j>1)
    tab[i-1][j-1]=bl_case_haut_gauche(tab[i-1][j-1],i,j);
	if(i>1)
	tab[i-1][j]=bl_case_haut_centre(tab[i-1][j],i,j);   
	if(i>1 && j<SIZE-1)
	tab[i-1][j+1]=bl_case_haut_droite(tab[i-1][j+1],i,j);   	   
    if(j>1)
	tab[i][j-1]=bl_case_milieu_gauche(tab[i][j-1],i,j);   
	if(j<SIZE-1)
	tab[i][j+1]=bl_case_milieu_droite(tab[i][j+1],i,j);   
	if(i<SIZE-1 && j>1)
	tab[i+1][j-1]=bl_case_bas_gauche(tab[i+1][j-1],i,j);   
	if(i<SIZE-1)
	tab[i+1][j]=bl_case_bas_centre(tab[i+1][j],i,j);   
	if(i<SIZE-1 && j<SIZE-1)
	tab[i+1][j+1]=bl_case_bas_droite(tab[i+1][j+1],i,j);   
   }
  }
 }
 
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
 														/*AFFICHE LE TABLEAUX B*/
 for(i=0;i<SIZE;i++)
 {
  for(j=0;j<SIZE;j++)
  {
   if(tab[i][j]==x)
   {
    pion_x=pion_x+1;
   }
  }
 }
 if(pion_x==0 && k==0)
 {
  printf("\t\t\t\t\tPAS DE POSSIBILITE DE RETOURNER UN PION ADVERSE\n");
  printf("\t\t\t\t\tJOUEUR NOIR");
  nr_detection(tab);
 }
 else if(k==0)
 {
  for(i=0;i<SIZE;i++)				 
  {									 
   printf("\n");
   for(j=0;j<SIZE;j++)				  
   {
    printf("\t%c",tab[i][j]);
    if(tab[i][j]==bl)
	 pion_b=pion_b+1;
    else if (tab[i][j]==nr)
	 pion_n=pion_n+1;
   }
   printf("\n");
  }
  printf("\n");
  printf("\npoint blanc :%d\t\tpoint noir :%d",pion_b,pion_n);
  printf("\n\t\t\t\t\tDONNER LA CASE DU PION :");
  printf("\n\nligne :");
  scanf("%d",&ligne);
  printf("\n\ncolonne :");
  scanf("%d",&colonne);
  if( ligne<SIZE && ligne>0 )
  {
   save=tab[ligne][colonne];
   if(save==x)
   {
    tab[ligne][colonne]=tmp;
    bl_return_pion(tab[ligne][colonne],ligne,colonne);
    printf("\t\t\t\t\tJOUEUR NOIR");
    nr_detection(tab);
   }
   else
   {
    do
    {
     do
	 {
	  printf("\n\t\t\t\t\tREDONNER LA CASE CORRESPONDANT AU '.'");
      printf("\n\nligne :");
      scanf("%d",&ligne);
      printf("\n\ncolonne :");
      scanf("%d",&colonne);
	 }
	 while(ligne>SIZE || ligne<0 || colonne>SIZE || colonne<0 );
     save=tab[ligne][colonne];
    }
    while(save != x);
    tab[ligne][colonne]=tmp;
    bl_return_pion(tab[ligne][colonne],ligne,colonne);
    printf("\t\t\t\t\tJOUEUR NOIR");
    nr_detection(tab);
   }
  }
  else
  {
   do
   {
    do
    {
     printf("\n\t\t\t\t\tREDONNER LA CASE CORRESPONDANT AU '.'");
     printf("\n\nligne :");
     scanf("%d",&ligne);
     printf("\n\ncolonne :");
     scanf("%d",&colonne);
    }
    while(ligne>SIZE || ligne<0 || colonne>SIZE || colonne<0 );
    save=tab[ligne][colonne];
   }
   while(save != x);
   tab[ligne][colonne]=tmp;
   bl_return_pion(tab[ligne][colonne],ligne,colonne);
   printf("\t\t\t\t\tJOUEUR NOIR");
   nr_detection(tab);
  }
 }
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_haut_gauche(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(i>2 && j>2)
  {
   do
   {
    if(i>2 && j>2)
	{
	case_next=tab[i-2][j-2];
    i=i-1;
    j=j-1;
    }
    else
    case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i-1][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_haut_centre(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(i>2)
  {
   do
   {
    if(i>2)
	{
	case_next=tab[i-2][j];
    i=i-1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i-1][j]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_haut_droite(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(i>2 && j<SIZE-2)
  {
   do
   {
    if(i>2 && j<SIZE-2)
	{
	case_next=tab[i-2][j+2];
    i=i-1;
    j=j+1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i-1][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_milieu_gauche(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(j>2)
  {
   do
   {
    if(j>2)
	{
	case_next=tab[i][j-2];
    j=j-1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_milieu_droite(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(j<SIZE-2)
  {
   do
   {
    if(j<SIZE-2)
	{
	case_next=tab[i][j+2];
    j=j+1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_bas_gauche(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(i<SIZE-2 && j>2)
  {
   do
   {
    if( i<SIZE-2 && j>2)
	{
	case_next=tab[i+2][j-2];
    i=i+1;
    j=j-1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i+1][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_bas_centre(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(i<SIZE-2)
  {
   do
   {
    if(i<SIZE-2)
	{
	case_next=tab[i+2][j];
    i=i+1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i+1][j]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_case_bas_droite(int  caract,int i,int j)
{
 if(caract==nr)
 {
  if(i<SIZE-2 && j<SIZE-2)
  {
   do
   {
    if(i<SIZE-2 && j<SIZE-2)
	{
	case_next=tab[i+2][j+2];
    i=i+1;
    j=j+1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i+1][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE DE RETOURNEMENT DES PIONS B*/
void bl_return_pion(int  caract,int ligne,int colonne)
{
 int i=ligne;		
 int j=colonne;
 int b=0;
 int n=0;
 if(i>1 && j>1)
 tab[i][j]=bl_return_ht_gch(tab[i-1][j-1],i,j);
 if(i>1)
 tab[i][j]=bl_return_ht_ct(tab[i-1][j],i,j);
 if(i>1 && j<SIZE-1)
 tab[i][j]=bl_return_ht_drt(tab[i-1][j+1],i,j);
 if(j>1)
 tab[i][j]=bl_return_ml_gch(tab[i][j-1],i,j);
 if(j<SIZE-1)
 tab[i][j]=bl_return_ml_drt(tab[i][j+1],i,j);
 if(i<SIZE-1 && j>1)
 tab[i][j]=bl_return_bs_gch(tab[i+1][j-1],i,j);
 if(i<SIZE-1)
 tab[i][j]=bl_return_bs_ct(tab[i+1][j],i,j);
 if(i<SIZE-1 && j<SIZE-1)
 tab[i][j]=bl_return_bs_drt(tab[i+1][j+1],i,j);
 for(i=0;i<SIZE;i++)
 {
  for(j=0;j<SIZE;j++)
  {
   if(tab[i][j]==x)
   {
    tab[i][j]=ab;
   }
  }
 }
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION SECONDAIRE DE RETOURNEMENT DES PIONS B*/
int  bl_return_ht_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i>1 && j>1)
  {
   do
   {
    test=tab[i-1][j-1];
    i=i-1;
    j=j-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col-1][lig-1];
     tab[col-1][lig-1]=bl;
     col=col-1;
     lig=lig-1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ht_ct(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test; 
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i>1)
  {
   do
   {
    test=tab[i-1][j];
    i=i-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col-1][lig];
     tab[col-1][lig]=bl;
     col=col-1;
    }
    while(case_tmp==nr);
    case_b=bl;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ht_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i>1 && j<SIZE-1)
  {
   do
   { 
    test=tab[i-1][j+1];
    i=i-1;
    j=j+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col-1][lig+1];
     tab[col-1][lig+1]=bl;
     col=col-1;
     lig=lig+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ml_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(j>1)
  {
   do
   {
    test=tab[i][j-1];
    j=j-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col][lig-1];
     tab[col][lig-1]=bl;
     lig=lig-1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ml_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1)
  {
   do
   {
    test=tab[i][j+1];
    j=j+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col][lig+1];
     tab[col][lig+1]=bl;
     lig=lig+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_bs_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1 && j>1)
  {
   do
   {
    test=tab[i+1][j-1];
    i=i+1;
    j=j-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col+1][lig-1];
     tab[col+1][lig-1]=bl;
     col=col+1;
     lig=lig-1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_bs_ct(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1)
  {
   do
   {
    test=tab[i+1][j];
    i=i+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col+1][lig];
     tab[col+1][lig]=bl;
     col=col+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_bs_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1 && j<SIZE-1)
  {
   do
   {
    test=tab[i+1][j+1];
    i=i+1;
    j=j+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col+1][lig+1];
     tab[col+1][lig+1]=bl;
     col=col+1;
     lig=lig+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE DE DETECTION DES PIONS N*/
void nr_detection(int  tab[SIZE][SIZE])
{
 int i;
 int j;
 int pion_b=0;
 int pion_n=0;
 int pion_x=0;
 int  save;
 for(i=0 ; i<SIZE ; i++)
 {
  for(j=0 ; j<SIZE ; j++)
  {
   if(tab[i][j]==nr)
   {
	if(i>1 && j>1)
    tab[i-1][j-1]=nr_case_haut_gauche(tab[i-1][j-1],i,j);
	if(i>1)
	tab[i-1][j]=nr_case_haut_centre(tab[i-1][j],i,j);   
	if(i>1 && j<SIZE-1)
	tab[i-1][j+1]=nr_case_haut_droite(tab[i-1][j+1],i,j);   	   
    if(j>1)
	tab[i][j-1]=nr_case_milieu_gauche(tab[i][j-1],i,j);   
	if(j<SIZE-1)
	tab[i][j+1]=nr_case_milieu_droite(tab[i][j+1],i,j);   
	if(i<SIZE-1 && j>1)
	tab[i+1][j-1]=nr_case_bas_gauche(tab[i+1][j-1],i,j);   
	if(i<SIZE-1)
	tab[i+1][j]=nr_case_bas_centre(tab[i+1][j],i,j);   
	if(i<SIZE-1 && j<SIZE-1)
	tab[i+1][j+1]=nr_case_bas_droite(tab[i+1][j+1],i,j);   
   }
  }
 }
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
 														/*AFFICHE LE TABLEAUX N*/
 for(i=0;i<SIZE;i++)
 {
  for(j=0;j<SIZE;j++)
  {
   if(tab[i][j]==x)
   {
    pion_x=pion_x+1;
   }
  }
 }
 if(pion_x==0)
 {
  k=k+1;
  printf("\t\t\t\t\tPAS DE POSSIBILITE DE RETOURNER UN PION ADVERSE\n");
  bl_detection(tab);
 }
 else
 {
  k=0;
  for(i=0;i<SIZE;i++)				 
  {									 
   printf("\n");
   for(j=0;j<SIZE;j++)				  
   {
    printf("\t%c",tab[i][j]);
    if(tab[i][j]==bl)
	 pion_b=pion_b+1;
    else if (tab[i][j]==nr)
	 pion_n=pion_n+1;
   }
   printf("\n");
  }
  printf("\n");
  printf("\npoint blanc :%d\t\tpoint noir :%d",pion_b,pion_n);
  printf("\n\t\t\t\t\tDONNER LA CASE DU PION :");
  printf("\n\nligne :");
  scanf("%d",&ligne);
  printf("\n\ncolonne :");
  scanf("%d",&colonne);
  if( ligne<SIZE && ligne>0 )
  {
   save=tab[ligne][colonne];
   if(save==x)
   {
    tab[ligne][colonne]=tmp;
    nr_return_pion(tab[ligne][colonne],ligne,colonne);
    printf("\t\t\t\t\tJOUEUR BLANC");
    bl_detection(tab);
   }
   else
   {
    do
    {
     do
	 {
	  printf("\n\t\t\t\t\tREDONNER LA CASE CORRESPONDANT AU '.'");
      printf("\n\nligne :");
      scanf("%d",&ligne);
      printf("\n\ncolonne :");
      scanf("%d",&colonne);
	 }
	 while(ligne>SIZE || ligne<0 || colonne>SIZE || colonne<0 );
     save=tab[ligne][colonne];
    }
    while(save != x);
    tab[ligne][colonne]=tmp;
    nr_return_pion(tab[ligne][colonne],ligne,colonne);
    printf("\t\t\t\t\tJOUEUR BLANC");
    bl_detection(tab);
   }
  }
  else
  {
   do
   {
    do
    {
     printf("\n\t\t\t\t\tREDONNER LA CASE CORRESPONDANT AU '.'");
     printf("\n\nligne :");
     scanf("%d",&ligne);
     printf("\n\ncolonne :");
     scanf("%d",&colonne);
    }
    while(ligne>SIZE || ligne<0 || colonne>SIZE || colonne<0 );
    save=tab[ligne][colonne];
   }
   while(save != x);
   tab[ligne][colonne]=tmp;
   nr_return_pion(tab[ligne][colonne],ligne,colonne);
   printf("\t\t\t\t\tJOUEUR BLANC");
   bl_detection(tab);
  }
 }
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_haut_gauche(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(i>2 && j>2)
  {
   do
   {
    if(i>2 && j>2)
	{
	case_next=tab[i-2][j-2];
    i=i-1;
    j=j-1;
	}
	else
	case_next=ab;
   }
   while(case_next==nr);
   if(case_next==nr)
   {
    tab[i-1][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_haut_centre(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(i>2)
  {
   do
   {
    if(i>2)
	{
	case_next=tab[i-2][j];
    i=i-1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i-1][j]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_haut_droite(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(i>2 && j<SIZE-2)
  {
   do
   {
    if(i>2 && j<SIZE-2)
	{
	case_next=tab[i-2][j+2];
    i=i-1;
    j=j+1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i-1][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_milieu_gauche(int  caract,int i,int j)
{
if(caract==bl)
 {
  if(j>2)
  {
   do
   {
    if(j>2)
	{
	case_next=tab[i][j-2];
    j=j-1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_milieu_droite(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(j<SIZE-2)
  {
   do
   {
    if(j<SIZE-2)
	{
	case_next=tab[i][j+2];
    j=j+1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_bas_gauche(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(i<SIZE-2 && j>2)
  {
   do
   {
    if(i<SIZE-2 && j>2)
	{
	case_next=tab[i+2][j-2];
    i=i+1;
    j=j-1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i+1][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_bas_centre(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(i<SIZE-2)
  {
   do
   {
    if(i<SIZE-2)
	{
	case_next=tab[i+2][j];
    i=i+1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i+1][j]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_case_bas_droite(int  caract,int i,int j)
{
 if(caract==bl)
 {
  if(i<SIZE-2 && j<SIZE-2)
  {
   do
   {
    if(i<SIZE-2 && j<SIZE-2)
	{
	case_next=tab[i+2][j+2];
    i=i+1;
    j=j+1;
	}
	else
	case_next=ab;
   }
   while(case_next==bl);
   if(case_next==nr)
   {
    tab[i+1][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE DE RETOURNEMENT DES PIONS N*/
void nr_return_pion(int  caract,int ligne,int colonne)
{
 int i=ligne;		
 int j=colonne;
 int b=0;
 int n=0;
 if(i>1 && j>1)
 tab[i][j]=nr_return_ht_gch(tab[i-1][j-1],i,j);
 if(i>1)
 tab[i][j]=nr_return_ht_ct(tab[i-1][j],i,j);
 if(i>1 && j<SIZE-1)
 tab[i][j]=nr_return_ht_drt(tab[i-1][j+1],i,j);
 if(j>1)
 tab[i][j]=nr_return_ml_gch(tab[i][j-1],i,j);
 if(j<SIZE-1)
 tab[i][j]=nr_return_ml_drt(tab[i][j+1],i,j);
 if(i<SIZE-1 && j>1)
 tab[i][j]=nr_return_bs_gch(tab[i+1][j-1],i,j);
 if(i<SIZE-1)
 tab[i][j]=nr_return_bs_ct(tab[i+1][j],i,j);
 if(i<SIZE-1 && j<SIZE-1)
 tab[i][j]=nr_return_bs_drt(tab[i+1][j+1],i,j);
 for(i=0;i<SIZE;i++)
 {
  for(j=0;j<SIZE;j++)
  {
   if(tab[i][j]==x)
   {
    tab[i][j]=ab;
   }
  }
 }
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION SECONDAIRE DE RETOURNEMENT DES PIONS N*/
int  nr_return_ht_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  if(i>1 && j>1)
  {
  do
  {
   test=tab[i-1][j-1];
   i=i-1;
   j=j-1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col-1][lig-1];
    tab[col-1][lig-1]=nr;
    col=col-1;
    lig=lig-1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_ht_ct(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test ;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  if(i>1)
  {
  do
  {
   test=tab[i-1][j];
   i=i-1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col-1][lig];
    tab[col-1][lig]=nr;
    col=col-1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_ht_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  if(i>1 && j<SIZE-1)
  {
  do
  {
   test=tab[i-1][j+1];
   i=i-1;
   j=j+1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col-1][lig+1];
    tab[col-1][lig+1]=nr;
    col=col-1;
    lig=lig+1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_ml_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  if(j>1)
  {
  do
  {
   test=tab[i][j-1];
   j=j-1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col][lig-1];
    tab[col][lig-1]=nr;
    lig=lig-1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_ml_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  if(j<SIZE-1)
  {
  do
  {
   test=tab[i][j+1];
   j=j+1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col][lig+1];
    tab[col][lig+1]=nr;
    lig=lig+1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_bs_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  if(i<SIZE-1 && j>1)
  {
  do
  {
   test=tab[i+1][j-1];
  i=i+1;
  j=j-1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col+1][lig-1];
    tab[col+1][lig-1]=nr;
    col=col+1;
    lig=lig-1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_bs_ct(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;
 if(case_b==bl)
 {
  do
  {
   test=tab[i+1][j];
  i=i+1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col+1][lig];
    tab[col+1][lig]=nr;
    col=col+1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  nr_return_bs_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=nr;
 i=col;
 j=lig;

 if(case_b==bl)
 {
  if(i<SIZE-1 && j<SIZE-1)
  {
  do
  {
   test=tab[i+1][j+1];
   i=i+1;
   j=j+1;
  }
  while(test==bl);
  if(test==nr)
  {
   do
   {
    case_tmp=tab[col+1][lig+1];
    tab[col+1][lig+1]=nr;
    col=col-1;
    lig=lig+1;
   }
   while(case_tmp==bl);
   case_b=nr;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
